<?php

namespace App\Http\Middleware\Admin;

use Closure;

class AuthMiddleware
{
    protected $except = [
        'admin/access/login'
    ];
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (\Admin::check() || $this->pass($request)) {
            return $next($request);
        }

        return redirect()->route('admin.login');
    }

    /**
     * @param  \Illuminate\Http\Request  $request
     *
     * @return bool
     */
    protected function pass($request)
    {
        foreach ($this->except as $except) {
            if ($request->is($except)) {
                return true;
            }
        }

        return false;
    }
}
